bitmask: Optimize no-op resizes
authorMatthias Clasen <mclasen@redhat.com>
Thu, 10 Sep 2015 22:48:29 +0000 (18:48 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 12 Sep 2015 15:24:37 +0000 (11:24 -0400)
Statistics for the gtk3-demo listbox example show that the
vast majority of calls to _gtk_allocated_bitmask_resize go
from a size of 2 to 2. Don't needlessly call realloc() in
this case.

gtk/gtkallocatedbitmask.c

index 567b86cb91b65551a5e2b7a93d14265475c658a0..0950d4362dec64489cf406a2596b113a3db1e723 100644 (file)
@@ -52,6 +52,9 @@ gtk_allocated_bitmask_resize (GtkBitmask *mask,
 {
   gsize i;
 
+  if (size == mask->len)
+    return mask;
+
   mask = g_realloc (mask, sizeof (GtkBitmask) + sizeof(VALUE_TYPE) * (size - 1));
 
   for (i = mask->len; i < size; i++)